<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button @click="generate">生成</button>
      <ul>
        <li v-for="(v, i) of numList">
          {{ v }} <button @click="del(i)">删除</button>
        </li>
      </ul>
    </div>

    <script src="vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          numList: [1, 5, 17],
        },
        methods: {
          del(i) {
            this.numList.splice(i, 1); // 会改变原数组，所以不用赋值
          },
          generate() {
            this.numList.push(Math.floor(Math.random() * 21));
          },
        },
      });
    </script>
  </body>
</html>
